public class Solution1816 {
    public String truncateSentence(String s, int k) {
        String[] strings=s.split(" ");
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(strings[0]);
        for (int i=1;i<k;i++){
            stringBuilder.append(' ').append(strings[i]);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1816().truncateSentence("Hello how are you Contestant",4));
    }
}

